package com.culture.bootdemo.utils;

import cn.hutool.core.util.DesensitizedUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

/**
 * @Author: wenjl
 * @Date: 2021/12/24 14:22
 * @Description: 正则工具类
 */
@Slf4j
public class RegularUtil {

    /**
     * 首位后脱敏
     *
     * @param name
     * @return
     */
    public static String getNickNameDesen(String name) {
        if (StringUtils.isBlank(name)) {
            return "";
        }
        log.info("getNickNameDesen 原数据nickname:{}", name);
        String substring = name.substring(0, 1);
        return substring + "*****";
    }

    /**
     * '@'字符前两位脱敏
     *
     * @param email
     * @return
     */
    public static String getEmailDesen(String email) {
        if (StringUtils.isBlank(email)) {
            return "";
        }
        log.info("getEmailDesen 原数据email:{}", email);
        email = email.replaceAll("\\w{2}(?=\\@)", "**");
        log.info("getEmailDesen 脱敏email:{}", email);
        return email;
    }

    public static void main(String[] args) {

//        DesensitizedUtil
        String email = DesensitizedUtil.email("213-32dws@sow.com");
        System.out.println(email);
    }
}
